/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
* File Name          : usb_endp.c
* Author             : MCD Application Team
* Version            : V3.1.0
* Date               : 10/30/2009
* Description        : Endpoint routines
********************************************************************************
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/

/* Includes ------------------------------------------------------------------*/
#include "usb_lib.h"
#include "usb_istr.h"

#include "usb_mdwr.h"

#include <stdio.h>

/**
 * $USBCONFIG - here we must, if necessary add / remove Callback and Endpoint.
 * See also usb_conf.h
 */

void EP1_IN_Callback(void)
{
	DataForEpInHandler data;

	data = (USB_EpInIrqHandlers[MDWR_NUM_IN_EP_0])();
	USB_SIL_Write(EP1_IN, data.pBufferPointer, data.wBufferSize);

	/* Enable the transmit of data on EP1 */
	SetEPTxValid(ENDP1);
}

void EP3_IN_Callback(void)
{
	DataForEpInHandler data;

	data = (USB_EpInIrqHandlers[MDWR_NUM_IN_EP_1])();
	USB_SIL_Write(EP3_IN, data.pBufferPointer, data.wBufferSize);

	/* Enable the transmit of data on EP3 */
	SetEPTxValid(ENDP3);
}

void EP2_OUT_Callback(void)
{
	uint8_t data[64];
	uint8_t nRead;

	nRead = USB_SIL_Read(EP2_OUT, data);
	(USB_EpOutIrqHandlers[MDWR_NUM_OUT_EP_0])(data, nRead);

    #ifndef STM32F10X_CL
		/* Allow endpoint to obtain the following command */
        SetEPRxStatus(ENDP2, EP_RX_VALID);
    #else
        if (GetEPRxStatus(EP2_OUT) == EP_RX_STALL)
        {
			// Allow endpoint to obtain the following command
            SetEPRxStatus(EP2_OUT, EP_RX_VALID);
        }
    #endif /* STM32F10X_CL */
}

void EP4_OUT_Callback(void)
{
	uint8_t data[64];
	uint8_t nRead;

	nRead = USB_SIL_Read(EP4_OUT, data);
	(USB_EpOutIrqHandlers[MDWR_NUM_OUT_EP_1])(data, nRead);

	#ifndef STM32F10X_CL
		/* Allow endpoint to obtain the following command */
        SetEPRxStatus(ENDP4, EP_RX_VALID);
    #else
        if (GetEPRxStatus(EP4_OUT) == EP_RX_STALL)
        {
			// Allow endpoint to obtain the following command
       		SetEPRxStatus(EP4_OUT, EP_RX_VALID);
        }
    #endif /* STM32F10X_CL */
}

/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
